package net.haiyue.api.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.haiyue.api.custom.JsonResult;
import net.haiyue.api.entity.Event;
import net.haiyue.api.entity.viewModel.EventViewModel4Request;
import net.haiyue.api.service.EventService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(value = "EventController")
@RestController
@RequestMapping(value = "/event")
public class EventController {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Resource
    private EventService _service;
    @Autowired
    HttpServletRequest request;

    @ApiOperation(value="获取所有的录入信息", notes="用于表格展示")
    @PostMapping("/index")
    public JsonResult Index(@RequestBody EventViewModel4Request param){
        String email = request.getHeader("email");
        param.setEmail(email);
        return JsonResult.success( _service.all(param));
    }

    @ApiOperation(value="新建一条记录")
    @PostMapping("/add")
    public JsonResult Add(@RequestBody Event event){
        return JsonResult.success( _service.add(event));
    }

    @ApiOperation(value="查询一条记录")
    @GetMapping("/single")
    public JsonResult single(@RequestParam(name = "id") Integer id){
        return JsonResult.success( _service.singleById(id));
    }


    @GetMapping("/selectModule")
    @ApiOperation(value="添加时拉取模块")
    public JsonResult selectModule(@RequestParam(name = "id") Integer id){
        String email = request.getHeader("email");
        return JsonResult.success( _service.selectModule(email,id));
    }


    @GetMapping("/del")
    @ApiOperation(value="删除一行记录")
    public JsonResult del(@RequestParam(name = "id") Integer id){
        _service.del(id);
        return JsonResult.success();
    }
}
